package com.shigu.itemCate.action;

import com.shigu.PageResponse;
import com.shigu.exceptions.WapException;
import com.shigu.hotItem.api.HotItemService;
import com.shigu.itemCate.api.ItemCateService;
import com.shigu.item.bo.GoodsListRequest;
import com.shigu.hotItem.bo.HotGoodsRequest;
import com.shigu.itemCate.vo.ChildCateVo;
import com.shigu.item.vo.GoodsListVo;
import com.shigu.hotItem.vo.HotGoodsVo;
import com.shigu.itemCate.vo.MainCateVo;
import com.shigu.user.service.MallTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/*
 * create by  过儿  2019-06-05
 *
 */
@Controller
@RequestMapping("wapsjson")
public class IndexItemController {
    @Resource(name = "itemCateServiceImpl")
    ItemCateService itemCateService;

    @Resource(name = "hotItemServiceImpl")
    HotItemService hotItemService;

    @Autowired
    MallTokenService mallTokenService;

    @RequestMapping("getMainCateList")
    @ResponseBody
    public PageResponse<MainCateVo> getMainCateList() {
        return itemCateService.getMainCateList();
    }

    @RequestMapping("getChildCateList")
    @ResponseBody
    public PageResponse<ChildCateVo> getChildCateList(String mainCateId) throws WapException {
        return itemCateService.getChildCateList(mainCateId);
    }

    @RequestMapping("getGoodsList")
    @ResponseBody
    public PageResponse<GoodsListVo> getGoodsList(GoodsListRequest request) {
        Long mallUserId = mallTokenService.selUserIdByToken(request.getToken());
        return itemCateService.getGoodsList(request.getPage(), request.getSize(), mallUserId,request.getSort(),
                                              request.getChildCateId(), request.getKeyword());
    }

    @RequestMapping("getHotGoodsList")
    @ResponseBody
    public  PageResponse<HotGoodsVo> getHotGoodsList(HotGoodsRequest request){
        Long mallUserId = mallTokenService.selUserIdByToken(request.getToken());
        return hotItemService.getHotGoodsList(request.getPage(),request.getSize(),request.getCateId(),mallUserId);
    }

}
